'''
Created on Nov 25, 2010

@author: Polido
'''

import pygame
from pygame.joystick import Joystick
from octorotor.joystick.JoystickData import JoystickData

#pygame init
pygame.init()
pygame.joystick.init()

class Controller(object):
    '''
    classdocs
    '''

    def __init__(self):
        '''
        Constructor
        '''
        try:
            self.j = Joystick(0) # create a joystick instance
            self.j.init() # init instance
            print 'Enabled joystick: ' + self.j.get_name()
        except pygame.error:
            print 'no joystick found.'
            
    def shouldStop(self):
        return self.j.get_button(0) | self.j.get_button(1) | self.j.get_button(2) | self.j.get_button(3)
            
    def getData(self):
        return JoystickData( self.j, self.shouldStop() )

#TODO: BAD: Do not make singleton, but using it for now for the JoystickValues and the Octorotor
Singleton = Controller()